{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Installation\n",
    "PyRosetta是Rosetta的重要Python接口，该大分子Python包提供了大量Rosetta底层的类和函数调用API，可以说PyRosetta是媲美大分子药物开发领域的“RDkit”。该Python接口是由JHU大学的Jeffery Gray教授实验室领头开发，随着近年来Python语言的大热，越来越多人采用PyRosetta进行开发。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1 PyRosetta的学术授权\n",
    "PyRosetta是学术开源，商业授权的获取模式。\n",
    "\n",
    "学术申请可通过以下链接进行申请: https://els.comotion.uw.edu/express_license_technologies/pyrosetta"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2 安装\n",
    "PyRosetta有两种很方便的安装模式:\n",
    "- Release预编译包安装\n",
    "- 通过conda源进行安装\n",
    "\n",
    "\n",
    "\n",
    "#### 2.1 通过Release的预编译包安装\n",
    "首先通过PyRosetta官方网站进行下载: http://www.pyrosetta.org/dow\n",
    "\n",
    "PyRosetta目前兼容2种平台: MacOS, Linux\n",
    "\n",
    "![Alt Text](./img/pyrosetta_install1.jpg)\n",
    "\n",
    "\n",
    "输入以下命令安装即可:\n",
    "\n",
    "```\n",
    "tar jxvf *.bz2\n",
    "cd /path/PyRosetta4.Release.python27.linux.release-215/setup\n",
    "python setup.py install\n",
    "```\n",
    "\n",
    "#### 2.2 通过Conda源安装\n",
    "在2019年，PyRosetta已经可以通过Conda方便的安装，更新管理十分方便，但是国内的网络...\n",
    "\n",
    "具体安装方式: \n",
    "\n",
    "1. 首先在编辑~/.condarc文件，添加PyRosetta的channel.\n",
    "\n",
    "```\n",
    "vi ~/.condarc\n",
    "```\n",
    "\n",
    "在~/.condarc文件添加以下内容，其中USERNAME:PASSWORD可通过授权网站获得。\n",
    "```\n",
    "channels:\n",
    "  - https://USERNAME:PASSWORD@conda.graylab.jhu.edu\n",
    "  - defaults\n",
    "```\n",
    "\n",
    "安装命令:\n",
    "```\n",
    "# 安装最新的PyRosetta版本:\n",
    "conda install pyrosetta\n",
    "\n",
    "# 安装特定版本的PyRosetta:\n",
    "conda install pyrosetta=<version>\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3. 测试PyRosetta安装是否成功"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "PyRosetta-4 2020 [Rosetta PyRosetta4.conda.mac.cxx11thread.serialization.python36.Release 2020.23+release.0d6f90a8cb9fa0567ca76bb71ee93bfe73340c70 2020-06-04T19:12:24] retrieved from: http://www.pyrosetta.org\n",
      "(C) Copyright Rosetta Commons Member Institutions. Created in JHU by Sergey Lyskov and PyRosetta Team.\n",
      "\u001b[0mcore.init: {0} \u001b[0mChecking for fconfig files in pwd and ./rosetta/flags\n",
      "\u001b[0mcore.init: {0} \u001b[0mRosetta version: PyRosetta4.conda.mac.cxx11thread.serialization.python36.Release r257 2020.23+release.0d6f90a8cb9 0d6f90a8cb9fa0567ca76bb71ee93bfe73340c70 http://www.pyrosetta.org 2020-06-04T19:12:24\n",
      "\u001b[0mcore.init: {0} \u001b[0mcommand: PyRosetta -ex1 -ex2aro -database /opt/miniconda3/envs/pyrosetta/lib/python3.6/site-packages/pyrosetta/database\n",
      "\u001b[0mbasic.random.init_random_generator: {0} \u001b[0m'RNG device' seed mode, using '/dev/urandom', seed=1730130464 seed_offset=0 real_seed=1730130464 thread_index=0\n",
      "\u001b[0mbasic.random.init_random_generator: {0} \u001b[0mRandomGenerator:init: Normal mode, seed=1730130464 RG_type=mt19937\n"
     ]
    }
   ],
   "source": [
    "from pyrosetta import *\n",
    "init()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果上述代码成功初始化没有报错，那么恭喜你。PyRosetta已经安装成功了！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. 在Jupyter Notebook中查询API\n",
    "在Notebook Lab中，原生就可以对一些PyRosetta的函数或则类的参数进行方便的查询。\n",
    "在下面尝试将光标移动到在init函数后，并按下**shitf+tab**吧。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<function pyrosetta.init(options='-ex1 -ex2aro', extra_options='', set_logging_handler=None, notebook=None, silent=False)>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "init"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![Alt Text](./img/pyrosetta_notebook_api.png)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 附录资源:\n",
    "- PyRosetta API文档: https://link.zhihu.com/?target=https%3A//graylab.jhu.edu/PyRosetta.documentation/\n",
    "- PyRosetta官方教程文档: https://link.zhihu.com/?target=http%3A//www.pyrosetta.org/tutorials\n",
    "- PyRosetta Notebook(官方): https://link.zhihu.com/?target=https%3A//github.com/RosettaCommons/PyRosetta.notebooks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pyrosetta",
   "language": "python",
   "name": "pyrosetta"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
